package com.frank.web.superadmin;


import com.frank.pojo.Area;
import com.frank.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/superadmin")
public class AreaController {
    private Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;

    @RequestMapping(value = "/listarea", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> listArea() {
        logger.info("------start------");
        long startTime = System.currentTimeMillis();

        Map<String, Object> map = new HashMap<>();
        List<Area> areas;
        try {
            areas = areaService.selectArea();
            map.put("rows", areas);
            map.put("total", areas.size());
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success", false);
            map.put("errMsg", e.toString());
        }
        long endTime = System.currentTimeMillis();
        logger.info("------start------");
        logger.debug("costTime:【{}ms】", endTime - startTime);
        logger.error("error___");
        return map;
    }

    // 指定响应的字符集为utf-8，解决中文乱码问题
    @RequestMapping(value = "/aaa", produces = {"text/plain;charset=utf-8", "text/html;charset=utf-8"})
    @ResponseBody
    public String hello() {
        return "hello,你好";
    }
}
